package com.nuc.zyt.day04.multiprocessing;

/**
 * @ClassName Demo
 * @Description TODO
 * @Author 耀酱
 * @Date 2023/5/29 19:41
 * @Version 1.0
 */

public class Demo{
    public static void main(String[] args) throws InterruptedException {
        Thread1 thread1 = new Thread1();
        Thread a = new Thread(thread1, "父亲");
        Thread b = new Thread(thread1,"儿子");
        // 获取默认线程优先级
        System.out.println(a.getName()+"线程优先级"+a.getPriority());
        System.out.println(b.getName()+"线程优先级"+b.getPriority());
        System.out.println(new Thread().getName()+"main线程优先级："+Thread.currentThread().getPriority());
        // 设置优先级
        a.setPriority(1);
        b.setPriority(10); // 尽可能让儿子线程先执行完毕
        System.out.println("设置优先级之后");

        System.out.println(a.getName()+"线程优先级"+a.getPriority());
        System.out.println(b.getName()+"线程优先级"+b.getPriority());
        System.out.println(new Thread().getName()+"main线程优先级："+Thread.currentThread().getPriority());

        // a.join(); // 将a线程插入到当前线程之前运行


        // 设置线程为守护线程
        a.setDaemon(true);  // 当儿子线程（非守护线程）结束，父亲线程（守护线程）也会陆续结束

        a.start();
        b.start();

        for (int i = 0; i < 10; i++) {
            System.out.println("main线程执行");
        }



    }
}
